package com.netx.cubigraf.backups;
import javax.servlet.ServletConfig;

import com.netx.cubigraf.shared.ApplicationInitializer;
import com.netx.generics.basic.Context;
import com.netx.generics.basic.RootContext;
import com.netx.generics.tasks.TaskManager;
import com.netx.generics.time.TimeValue;
import com.netx.generics.time.TimeValue.MEASURE;
import com.netx.generics.io.FileSystem;


public class SrvInitializer extends ApplicationInitializer {

	public SrvInitializer() {
		super();
	}
	
	public void ebsInit(ServletConfig config) throws Throwable {
		super.ebsInit(config);
		RootContext rootCtx = Context.getRootContext();
		TaskManager tm = (TaskManager)rootCtx.getProperty("task-manager").objectValue();
		FileSystem fileServer = (FileSystem)rootCtx.getProperty("servers/file-server").objectValue();
		// Daemon copy tasks:
		// schedule the task to run every minute:
		DaemonTask daemonCopy = new DaemonTask(getEbsContext().getDatabase(), tm, fileServer);
		rootCtx.getTimer().scheduleAtFixedRate(daemonCopy, 0, TimeValue.convert(1, MEASURE.MINUTES, MEASURE.MILLISECONDS));
	}

	public void ebsDestroy() throws Throwable {
		super.ebsDestroy();
	}
}
